package com.hdyg.sixg.activity.trans;

import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.hdyg.sixg.R;
import com.hdyg.sixg.activity.common.BaseActivity;
import com.hdyg.sixg.mvp.Contrant.CMining;
import com.hdyg.sixg.mvp.base.BaseUrl;
import com.hdyg.sixg.mvp.base.GetParamUtil;
import com.hdyg.sixg.mvp.base.SpMsg;
import com.hdyg.sixg.mvp.presenter.PMining;
import com.hdyg.sixg.util.ImageLoadUtil;
import com.hdyg.sixg.util.StringUtil;

import butterknife.BindView;


/**
 * @author CZB
 * @describe 挖矿
 * @time 2019/4/22 18:29
 */
public class MiningActivity extends BaseActivity implements CMining.IVMining {

    @BindView(R.id.iv_gif)
    ImageView ivGif;
    @BindView(R.id.iv_gif2)
    ImageView ivGif2;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.bt_mini)
    Button btMini;

    private String mineId;
    private CMining.IPMining mPresenter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_mining;
    }

    @Override
    protected void initView() {
        mineId = getIntent().getStringExtra(SpMsg.INTENT_STR);
        onClickListener();
        setImageGifShowHide(true);
        ImageLoadUtil.loadGif(mContext, R.mipmap.mining_1, ivGif);
        ImageLoadUtil.loadGif(mContext, R.mipmap.mining_2, ivGif2);
    }

    private void onClickListener() {
        ivBack.setOnClickListener(v -> finish());
        //挖矿按钮
        btMini.setOnClickListener(v -> {
            if (StringUtil.isFastDoubleClick()) {
                return;
            }
            mPresenter.pGetMining(BaseUrl.MINING_URL, GetParamUtil.getMiningParam(mineId));
        });
    }

    /**
     * 改变gif图
     * @param flag true未挖矿gif  false挖矿gif
     */
    private void setImageGifShowHide(boolean flag){
        if (flag){
            ivGif.setVisibility(View.VISIBLE);
            ivGif2.setVisibility(View.GONE);
        }else {
            ivGif.setVisibility(View.GONE);
            ivGif2.setVisibility(View.VISIBLE);
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void createPresenter() {
        mPresenter = new PMining(this);
    }

    @Override
    public void vGetMiningSuccess(String dataBean) {
        toastNotifyShort(dataBean);
        setImageGifShowHide(false);
    }

    @Override
    public void vGetMiningFail(String dataBean) {
        ImageLoadUtil.loadGif(mContext, R.mipmap.mining_1, ivGif);
        setImageGifShowHide(true);
    }
}
